<!DOCTYPE html>

<style>
    .layui-unselect layui-form-select .layui-input{width:300px;}
</style>
<html>
{include file="public/header" /}

<body>


<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <!--<div class="layui-card-header">财务报表,提现管理</div>-->
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">信息管理</li>
                            <!--<li onclick="go('add_cases')">新增案例</li>-->
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">

                                <div>
                                    <div class="layui-btn-group">
                                        <!--<button class="layui-btn ">推荐</button>-->
                                        <button class="layui-btn " onclick="del2();">批量删除</button>
                                        <!--<button class="layui-btn" >批量操作1</button>-->
                                    </div>

                                    <div class="layui-inline" style="float: right">
                                        <form class="layui-form" action="">
                                            <div class="layui-form-item" style="margin-bottom: 0px">

                                                <div class="layui-inline" style="margin-right: 0px">
                                                    <!--<label class="layui-form-label">密码</label>-->
                                                    <div class="layui-input-inline" style="width:800px;">
                                                        <div class="layui-input-inline">
                                                            <input type="text" name="depart_time" id="date"
                                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                                        </div>

                                                        <div class="layui-input-inline">
                                                            <input type="text" name="end_time" id="date2"
                                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                                        </div>

                                                        <div class="layui-input-inline">
                                                            <select name="type"  >
                                                                <option value="" selected=""></option>
                                                                <option value="1" >乘客</option>
                                                                <option value="2">司机</option>

                                                            </select>
                                                        </div>
                                                        <div class="layui-input-inline">
                                                            <input type="text" name="keyword" autocomplete="off" placeholder="请输入路线或电话号码"
                                                                   class="layui-input" >
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="layui-inline" style="margin-right: 0px">

                                                    <div class="layui-btn-group layui-inline" style="margin: 0px">
                                                        <!--此重置 仅仅是个跳转链接-->
                                                        <button  onclick="go('index')" class="layui-btn layui-btn-primary">重置</button>
                                                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">
                                                            <i class="layui-icon">&#xe615;</i>查找
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>

                                <div class="layadmin-trailer ">
                                    <table class="layui-table" lay-skin="line">
                                        <thead>
                                        <tr>
                                            <th style="width: 5%;"></th>
                                            <!--<th>#ID</th>-->
                                            <th>路线</th>
                                            <th>起始位置</th>
                                            <th>终点位置</th>
                                            <th>联系方式</th>
                                            <th>出发时间</th>
                                            <th>发布时间</th>
                                            <th>类型</th>
                                            <th>状态</th>

                                            <th style="width: 150px"></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="(item,index) in items" :data_id="item.id">
                                            <td style="width: 20px;text-align: center">
                                                <input type="checkbox" class="vue_index" name="id" :value="item.id"
                                                       style="zoom: 150%">
                                            </td>
                                            <!--<td>{{item.id}}</td>-->
                                            <td>{{item.content}}</td>
                                            <td>{{item.begin_place}}</td>
                                            <td>{{item.end_place}}</td>
                                            <td>{{item.phone}}</td>
                                            <td>{{item.depart_time}}</td>
                                            <td>{{item.create_time}}</td>

                                            <td  v-if="item.type == 1">乘车</td>
                                            <td  v-if="item.type == 2">载客</td>
                                            <!--<td>{{item.status}}</td>-->
                                            <td  v-if="item.status == -1">过期</td>
                                            <td  v-if="item.status == 0">发布中</td>
                                            <td  v-if="item.status == 1">行驶中</td>
                                            <td  v-if="item.status == 2">已完成</td>
                                            <td  v-if="item.status == 3">取消行程</td>

                                            <td style="text-align: center">

                                                <div class="layui-btn-group">
                                                    <a class="layui-btn layui-btn-sm layui-btn-primary"
                                                       onclick="del(this)"
                                                       :data_id="item.id" :data_index="index">
                                                      删除
                                                    </a>

                                                    <!--<a class="layui-btn layui-btn-sm layui-btn-primary"-->
                                                       <!--onclick="hre(this)"-->
                                                       <!--:data_id="item.id" :data_index="index">-->
                                                        <!--内容管理-->
                                                    <!--</a>-->
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div id="demo7"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前页
            items: []
        }
    });



    //初始数据
    function init() {
        layer.load(2);
        $.get('/admin/sunfc.Publish/index',{page:app.curr,limit:app.limit},
            function (res) {
                layer.closeAll();
                app.items = res.data;
            }
        );
    }


    //单独删除一条数据
    function del(that) {
        var id=$(that).attr('data_id');
        var index = layer.confirm('确认继续执行？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.post('{:url("del")}', {id: id}, function (res) {
                parent.layer.close(index);
                    if (res.code == 1) {
                         parent.layer.msg(res.msg, {icon: 1})
                         init();
                         return false;
                    }
                    else {
                         parent.layer.msg(res.msg, {icon: 2})
                         return false;
                    }
            });
        }, function () {
            parent.layer.close(index);
        });
    }

    //按需引入layui模块
    layui.use(['laypage', 'layer','table','element'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        var table = layui.table;
        var elemnet = layui.element;
        //完整功能
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"
            , limits: [10, 20]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                // console.log(obj)
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();
            }
        });

    });

    //获取批量IDS
    function getCheckBox() {
        var check = [];
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            check.push($(this).val());
        });
        return check;
    }
    //批量删除数据
    function del2() {
        var ids = getCheckBox();
        if (ids.length > 0) {
            var index = layer.confirm('确认继续执行？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post('{:url("pidel")}', {ids: ids}, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1});
                        $("input:checkbox").removeAttr("checked");
                        init();
                    }
                    layer.close(index);
                });
            }, function () {
                layer.close(index);
            });
        }
    }


    // 按需引入layui模块
    layui.use(['laypage', 'layer', 'table', 'element'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        var table = layui.table;
        var element = layui.element;
        var form = layui.form;
        element.on('tab(docDemoTabBrief)', function (data) {
//            console.log(this); //当前Tab标题所在的原始DOM元素
//            console.log(data.index); //得到当前Tab的所在下标
//            console.log(data.elem); //得到当前的Tab大容器
            if (data.index == 0) {
                init();
            }
        });

        /* 监听提交 */
        form.on('submit(component-form-demo1)', function (data) {

            $.post("{:url('add')}", data.field, function (res) {
                if (res.code == 1) {
                    parent.layer.msg(res.msg, {icon: 1})
                    return false;
                } else {
                    parent.layer.msg(res.msg, {icon: 2})
                    return false;
                }
            });


            return false;
        });

        init();


    });

    //Demo
    layui.use('form', function () {
        var form = layui.form;


        // 监听提交 进行搜索查询
        form.on('submit(formDemo)', function (data) {

            layer.load(2);
            $.get('/admin/sunfc.Publish/cases_search', data.field,
                function (res) {
                    layui.use(['laypage'], function () {
                        var laypage = layui.laypage;
                        //完整功能
                        laypage.render({
                            elem: 'demo7'
                            , count: res.total
                            , limits: [10, 20]
                            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                            , jump: function (obj) {
                                // console.log(obj)
                                app.curr = obj.curr;
                                app.limit = obj.limit;
                                layer.load(2);
                                $.get('/admin/sunfc.Publish/cases_search', {
                                        page: app.curr,
                                        limit: app.limit,
                                        keyword: data.field.keyword,
                                        type:data.field.type,
                                        depart_time:data.field.depart_time,
                                        end_time:data.field.end_time
                                    },
                                    function (res) {
                                        layer.closeAll();
                                        app.items = res.data;
                                    }
                                );
                            }
                        });
                    });
                }
            );
            return false;
        });

    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date',
            value:''
        });
        laydate.render({
            elem: '#date2',
            value:''
        });




    });

</script>


</body>
</html>




